package com.roncoo.eshop.inventory.request;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Copyright: Copyright (c) 2019 Hu-Cheng
 * 
 * @ClassName: RequestQueue.java
 * @Description: 请求内存队列
 *
 * @version: v1.0.0
 * @author: hucheng
 * @date: 2019年9月19日 上午10:26:47
 *
 */
public class RequestQueue {

	/**
	 * 创建内存集合
	 */
	private List<ArrayBlockingQueue<Request>> queues = new ArrayList<>();
	
	/**
	 * 标志是否刷新
	 */
	private Map<Integer, Boolean> flagMap = new ConcurrentHashMap<>();

	/**
	 * 添加内存队列到内存集合中去
	 * 
	 * @param queue
	 */
	public void addQueue(ArrayBlockingQueue<Request> queue) {
		this.queues.add(queue);
	}

	/**
	 * Copyright: Copyright (c) 2019 Hu-Cheng
	 * 
	 * @ClassName: RequestQueue.java
	 * @Description: 内部静态类实现单利模式
	 *
	 * @version: v1.0.0
	 * @author: hucheng
	 * @date: 2019年9月19日 上午10:33:56
	 *
	 */
	private static class Singleton {

		private static RequestQueue requestQueue;

		static {
			requestQueue = new RequestQueue();
		}

		public static RequestQueue getRequestQueue() {
			return requestQueue;
		}

	}

	public static RequestQueue getInstance() {
		return Singleton.getRequestQueue();
	}

	public int queueSize() {
		return queues.size();
	}

	public ArrayBlockingQueue<Request> getQueue(int index) {
		return queues.get(index);
	}
	
	public Map<Integer, Boolean> getFlagMap() {
		return flagMap;
	}

}
